<?php
/**
 * Created by PhpStorm.
 * User: yangkang
 * Date: 2018/3/14
 * Time: 上午10:29
 */

namespace App\Services\Mobile;


use App\Http\Requests\RecordStoreFastFormRequest;
use App\Mail\NotifyAdmin;
use App\Repositories\RecordRepository;
use App\Repositories\UserRepository;
use Illuminate\Support\Facades\Mail;

class RecordService
{
    private $recordRepository;
    private $userRepository;

    public function __construct(RecordRepository $recordRepository, UserRepository $userRepository)
    {
        $this->recordRepository = $recordRepository;
        $this->userRepository = $userRepository;
    }

    public function createProfile($productId)
    {
        session(['productId' => $productId]);
    }

    public function store($productId, $data)
    {
        $data['product_id'] = $productId;
        $data['mobile'] = session('mobile');
        $data['create_time'] = date('Y-m-d H:i:s');

        $user = $this->userRepository->getUserByMobile(session('mobile'));
        $data['name'] = $user->name;

        $data['origin_id'] = !empty(session('originId')) ? session('originId') : 0;
        $data['status'] = 0;

        $this->userRepository->storeRecord($user, $productId, $data);
    }

    public function storeFast($record)
    {
        $record['create_time'] = date('Y-m-d H:i:s');
        $record['origin'] = 'FAST';

        $record['origin_id'] = !empty(session('originId')) ? session('originId') : 0;
        $record['status'] = 0;
        $this->recordRepository->store($record);
    }

}